package com.miplus.ccrm.common;

public class JThreadEvent {
    protected final Object lock = new Object();

    public JThreadEvent()
    {
    }

    public boolean WaitOne(long ms) throws IllegalArgumentException,IllegalMonitorStateException,InterruptedException
    {
        long dw=System.currentTimeMillis();
        synchronized (lock) {
            //此方法timeout不产生异常，正常返回
            //wait()内部实际上先将synchronized锁定的锁释放
            lock.wait(ms);
        }
        if(System.currentTimeMillis()-dw>=ms)
            return false;
        return true;
    }

    public void SetEvent() throws IllegalMonitorStateException
    {
        synchronized (lock) {
            lock.notify();
        }
    }
}
